package com.fr.lintcode;

import java.util.Stack;

public class Q1317 {

    /**
     * @param root: root of complete binary tree
     * @return: the number of nodes
     */
    public int countNodes(TreeNode root) {
        // write your code here
    	if(root == null){
    		return 0;
    	}
    	int count = 0;
    	Stack<TreeNode> stack = new Stack<>();
    	stack.push(root);
    	while(!stack.isEmpty()){
    		TreeNode node = stack.pop();
    		count++;
    		if(node.left != null){
    			stack.push(node.left);
    		}
    		if(node.right != null){
    			stack.push(node.right);
    		}
    	}
    	return count;
    }

}
